//
//  DownloadData.m
//  Pictorial
//
//  Created by SKY on 15/12/30.
//  Copyright © 2015年 sky. All rights reserved.
//

#import "DownloadData.h"

@implementation DownloadData

+(void)saveDownloadData:(NSArray *)array{
    
    [[NSUserDefaults standardUserDefaults] setObject:array forKey:DOWNLOAD_DATA];
    [[NSUserDefaults standardUserDefaults] synchronize];
    
}
+(DownloadModel *)modelFromDataAtIndex:(NSInteger)index{
    NSArray *array = [self downloadData];
    NSData *data = array[index];
    DownloadModel *model = [NSKeyedUnarchiver unarchiveObjectWithData:data];
    return model;
}
+(void)addPicture:(DownloadModel *)model{
    
    NSData *data = [NSKeyedArchiver archivedDataWithRootObject:model];
    
    NSMutableArray *array = [NSMutableArray arrayWithArray: [[NSUserDefaults standardUserDefaults]objectForKey:DOWNLOAD_DATA]];
    [array addObject:data];

    [self saveDownloadData:array];
}
+(void)deletePictureAtIndex:(NSInteger)index{
    
    NSData *data = [DownloadData downloadData][index];
    
    NSMutableArray *array = [NSMutableArray arrayWithArray: [[NSUserDefaults standardUserDefaults] objectForKey:DOWNLOAD_DATA]];
    
    [array removeObject:data];
    
    [self saveDownloadData:array];
}
+(NSArray *)downloadData{
    return [[NSUserDefaults standardUserDefaults]objectForKey:DOWNLOAD_DATA];
}
@end
